package org.chnxi.study.springcloud.dubbo.storage.service.impl;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.dubbo.config.annotation.Service;
import org.chnxi.study.springcloud.dubbo.dto.*;
import org.chnxi.study.springcloud.dubbo.storage.dto.StorageDto;
import org.chnxi.study.springcloud.dubbo.storage.service.IStorageService;
import org.dromara.soul.client.dubbo.common.annotation.SoulDubboClient;
import org.springframework.beans.factory.annotation.Value;

import java.util.UUID;
import java.util.concurrent.TimeUnit;

@Slf4j
@SoulDubboClient(path="/storage")
@DubboService(version = "1.0.0", timeout = 500)
public class StorageServiceImpl implements IStorageService {

    @SoulDubboClient(path = "/buy", desc="演示购买")
    @Override
    public StorageDto buy(StorageDto storageDto) {
        log.info("8001--->>>>>");
        storageDto.setName("8001");
        storageDto.setCount(storageDto.getCount()+100);
        return storageDto;
    }

    @SoulDubboClient(path = "/second", desc="演示购买second")
    @Override
    public RpcResponse<StorageDto> second(String data) {
        StorageDto storageDto = new StorageDto();
        storageDto.setName("8001");
        storageDto.setCount(100);

        RpcResponse<StorageDto> response = new RpcResponse<>();
        response.setTransaction(TransactionDescrib.newInstance4Response(null));
        response.setResponder(ApplicationDescrib.getInstance());
        response.setPerformance(PerformanceDescrib.newInstance4Response(null));
        response.setStatus(RpcStatus.SUCCESS);
        response.setBusiData(storageDto);
        return response;
    }

    @SoulDubboClient(path = "/three", desc="演示购买three")
    @Override
    public RpcResponse<StorageDto> three(RpcRequest<StorageDto> request) {
        StorageDto storageDto = request.getBusiData();
        storageDto.setName("three");
        storageDto.setCount(200);
        return RpcResponse.buildSuccessDataWithRequest(request , storageDto);
    }
}
